/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package enteties.article;

import java.util.ArrayList;
import java.util.Collection;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import util.article.PriceClassDetails;

/**
 *
 * @author Joris
 */
@Stateless
public class PriceclassFacade extends AbstractFacade<Priceclass> implements PriceclassFacadeLocal {
    @PersistenceContext(unitName = "Liebaut-ejbPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public PriceclassFacade() {
        super(Priceclass.class);
    }
    
    @Override
    public Priceclass createPriceClass(PriceClassDetails pcd){
        Priceclass pc = new Priceclass();
        pc.setName(pcd.getName());
        create(pc);
        return pc;
    }
    
    
    
    @Override
    public PriceClassDetails convert (Priceclass pc){
        if(pc == null)
            return null;
        return new PriceClassDetails(pc.getId(), pc.getName(), pc.getDescription());
    }
    
    @Override
    public Collection<PriceClassDetails> convert (Collection<Priceclass> priceClasses){
        Collection<PriceClassDetails> details = new ArrayList<PriceClassDetails>();
        for(Priceclass priceClass : priceClasses){
            details.add(convert(priceClass));
        }
        return details;
    }
    
}
